package com.gkzf.ai.module.crm.controller.admin.creditReport;

import com.gkzf.ai.framework.common.pojo.CommonResult;
import com.gkzf.ai.framework.common.util.object.BeanUtils;
import com.gkzf.ai.module.crm.config.NoRepeatSubmit;
import com.gkzf.ai.module.crm.controller.admin.creditReport.vo.admittancecondition.CreditReportAdmittanceConditionSaveReqVO;
import com.gkzf.ai.module.crm.controller.admin.creditReport.vo.admittancecondition.UserCreditReportAdmittanceConditionRespVO;
import com.gkzf.ai.module.crm.dal.dataobject.creditReport.UserCreditReportAdmittanceConditionDO;
import com.gkzf.ai.module.crm.service.creditReport.CreditReportAdmittanceConditionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.gkzf.ai.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - CRM 征信报告对应准入条件")
@RestController
@RequestMapping("/crm/credit-report-admittance-condition")
@Validated
public class CreditReportAdmittanceConditionController {

    @Resource
    private CreditReportAdmittanceConditionService creditReportAdmittanceConditionService;



    @PutMapping("/update")
    @PermitAll
    @NoRepeatSubmit(value = "更新准入")
    @Operation(summary = "更新CRM 征信报告对应准入条件")
    public CommonResult<Boolean> updateCreditReportAdmittanceCondition(@Valid @RequestBody CreditReportAdmittanceConditionSaveReqVO updateReqVO) {
        creditReportAdmittanceConditionService.updateCreditReportAdmittanceCondition(updateReqVO,1);
        return success(true);
    }


    @GetMapping("/get")
    @Operation(summary = "获得CRM 用户征信报告对应准入条件")
    @Parameter(name = "creditBasicId", description = "basicId", required = true, example = "1024")
    @Parameter(name = "source", description = "0 详版  1简版 ", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:userCreditReportAdmittanceCondition:query')")
    public CommonResult<UserCreditReportAdmittanceConditionRespVO> getUserCreditReportAdmittanceCondition(@RequestParam("creditBasicId") Long creditBasicId) {
        UserCreditReportAdmittanceConditionDO userCreditReportAdmittanceCondition =
                creditReportAdmittanceConditionService.getCreditReportAdmittanceCondition(creditBasicId);
        return success(BeanUtils.toBean(userCreditReportAdmittanceCondition, UserCreditReportAdmittanceConditionRespVO.class));
    }



}